/**
 * @author wangjingjing 粮油旧版oa发文查询文件列表
 */
var sort = null;
var grid = null;
var typestore = null;
var biaoti = '查阅文件';
function initfawenlist() {

	Ext.BLANK_IMAGE_URL = Ext.get('basePath').getValue()
			+ "ajaxFramework/ext-2.1/resources/images/default/s.gif";

	Ext.menu.RangeMenu.prototype.icons = {
		gt : './ajaxFramework/ext-2.1/img/greater_then.png',
		lt : './ajaxFramework/ext-2.1/img/less_then.png',
		eq : './ajaxFramework/ext-2.1/img/equals.png'
	};
	Ext.grid.filter.StringFilter.prototype.icon = './ajaxFramework/ext-2.1/img/find.png';

	var colModel = new Ext.grid.ColumnModel([ {
		header : '年度',
		dataIndex : 'wenyear',
		width : 80,
		sortable : true
	}, {
		header : '发文号',
		width : 160,
		dataIndex : 'wenhaotype'
	}, {
		header : '标题',
		width : 500,
		dataIndex : 'biaoti'
	}, {
		header : '日期',
		dataIndex : 'fawendatetime',
		menuDisabled : true,
		width : 120,
		sortable : true
	}, {
		header : '操作',
		dataIndex : 'operate',
		menuDisabled : true
	} ]);

	var datearray = new Array();
	var min = parseInt($("input[name=min]").attr("value"));
	var max = parseInt($("input[name=max]").attr("value"));
	alert(min);
	alert(max);
	for ( var i = min; i <= max; i++) {
		datearray.push(i.toString());
	}

	var filters = new Ext.grid.GridFilters({
		cleanParams : function(p) { // 清除参数的方法，要保留PagingToolbar分页用的两个参数
			// var regex = new RegExp("^" + this.paramPrefix + "\[[0-9]+\]");
			for ( var key in p) {
				if (key != 'start' && key != 'limit')
					// if(regex.test(key)) {
					delete p[key];
				// }
			}
		},
		buildQuery : function(filters) {
			// filters 就是getFilterData返回的值, 代码中push入去的对象
			var p = {};
			for ( var i = 0, len = filters.length; i < len; i++) {
				var f = filters[i];

				// 取得在GridFilters中定义的filters中的一个filter
				var filter = this.getFilter(f.field);
				// 取得传递到server的参数名称
				var name = (filter.paramName ? filter.paramName
						: filter.dataIndex);
				var value = (filter.paramValue ? filter.paramValue
						: f.data['value']);
				if (value != '')
					p[name] = value;
			}
			var maintypeid = Ext.get('maintypeid').getValue();
			p['maintypeid']=maintypeid;
			return p;
		},
		filters : [ {
			type : 'string',
			dataIndex : 'biaoti'
		}, {
			type : 'string',
			dataIndex : 'wenhaotype'
		}, {
			type : 'list',
			dataIndex : 'wenyear',
			options : datearray
		}]
	});

	var url = Ext.get('url').getValue();
	sort = new Ext.data.JsonStore({
		url : url,
		fields : [ 'wenyear', 'wenhaotype', 'biaoti', 'fawendatetime',
				 'operate' ],
		root : 'root',
		totalProperty : 'totalProperty'
	});

	var bbar = new Ext.PagingToolbar({
		pageSize : 20,
		store : sort,
		displayInfo : true,
		plugins : filters,
		emptyMsg : '没有记录'
	});

	grid = new Ext.grid.GridPanel({
		
		cm : colModel,
		renderTo : 'topic-grid',
		store : sort,
		loadMask : true,
		height : $(window).height() - 55,
		bbar : bbar,
		plugins : filters
	});
	sort.load({
		params : {
			start : 0,
			limit : 20
		}
	});
}

function typeselect(){
		sort.reload({params:{start:0, limit: 20}});	
}
